package com.jeesuite.admin.controller.admin;

import java.util.Date;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jeesuite.admin.dao.entity.UserEntity;
import com.jeesuite.admin.model.WrapperResponseEntity;
import com.jeesuite.admin.model.request.GantPermRequest;
import com.jeesuite.admin.model.request.ModPassRequest;
import com.jeesuite.admin.util.SecurityUtil;
import com.jeesuite.common.util.DigestUtils;

@Controller
@RequestMapping("/admin/user")
public class UserAdminController {

	
	@RequestMapping(value = "add", method = RequestMethod.POST)
	public ResponseEntity<WrapperResponseEntity> addUser(@RequestBody UserEntity param){
		SecurityUtil.requireSuperAdmin();
		param.setPassword(DigestUtils.md5WithSalt(param.getPassword(), param.getName()));
		param.setCreatedAt(new Date());
		return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(param),HttpStatus.OK);
	}
	
	@RequestMapping(value = "modify_pass", method = RequestMethod.POST)
	public ResponseEntity<WrapperResponseEntity> modifyPassword(@RequestBody ModPassRequest param){
		
		return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
	}
	
	@RequestMapping(value = "gant_permission", method = RequestMethod.POST)
	public ResponseEntity<WrapperResponseEntity> gantPermission(@RequestBody GantPermRequest param){
		SecurityUtil.requireSuperAdmin();
		return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
	}
}
